<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('薪资变动添加员工')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>

</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>工号：</p>
                            <input type="text" name="badge"/>
                        </li>
                        <li>
                            <p>姓名：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="aa()">
                <i class="fa fa-plus"></i> 添加员工
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<script th:inline="javascript">
    var prefix = ctx + 'salaryChange/salaryChange';
    $(function () {
        queryData();
    })

    function queryData() {
        var columns = [];
        var checkbox = {checkbox: true};
        var Badge = {field: 'Badge', title: '工号'};
        var Name = {field: 'Name', title: '姓名'};
        var compName = {field: 'compName', title: '公司'};
        var depName = {field: 'depName', title: '部门名称'};
        var jobName = {field: 'jobName', title: '岗位'};
        var empStatusName = {field: 'empStatusName', title: '员工状态'};
        var jobStatusName = {field: 'jobStatusName', title: '在岗状态'};
        var empTypeNam = {field: 'empTypeNam', title: '员工类型'};
        var empGradeName = {field: 'empGradeName', title: '员工级别'};
        var idTypeName = {field: 'idTypeName', title: '证件类型'};
        var IDCard = {field: 'IDCard', title: '证件编号'};
        var empStartDate = {field: 'empStartDate', title: '入职日期'};
        var empEndDate = {field: 'empEndDate', title: '离职日期'};
        var payGradeName = {field: 'payGradeName', title: '薪资级别'};
        var costcenterName = {field: 'costcenterName', title: '成本中心'};
        var pzidName = {field: 'pzidName', title: '薪资区域'};
        var pcid = {field: 'pcid', title: '薪资城市'};
        var startDate = {field: 'startDate', title: '起薪日期'};
        var endDate = {field: 'endDate', title: '止薪日期'};
        var payTime = {field: 'payTime', title: '薪资时间'};
        var bcid = {field: 'bcid', title: '银行'};
        var bcCard = {field: 'bcCard', title: '银行卡号'};
        var bcName = {field: 'bcName', title: '报盘姓名'};
        var remark = {field: 'remark', title: '备注'};

        columns.push(checkbox, Badge, Name, compName, depName, jobName, empStatusName, jobStatusName, empTypeNam);
        columns.push(empGradeName, idTypeName, IDCard, empStartDate, empEndDate, payGradeName, costcenterName);
        columns.push(pzidName, pcid, startDate, endDate, payTime, bcid, bcCard, bcName, remark);

        var options = {
            code: "peid",
            uniqueId: "peid",
            url: prefix + '/findChangeEmp',
            modalName: "添加员工",
            height: $(window).height() - 110,
            columns: columns
        };
        $.table.init(options);
    }

    function add() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        }
        var allPeid = "";
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allPeid += row[i].peid
            } else {
                allPeid += row[i].peid + ","

            }
        }
        $.ajax({
            async: false,
            url: prefix + "/addSalaryChangeEmpProcedure",
            data: {
                "allPeid": allPeid
            },
            type: "post",
            dataType: "json",
            success: function (data) {

                //todo 这里需要判断data返回值
                if (data.code == 0) {
                    $.modal.alertWarning("添加成功！");
                    $.modal.close();
                    $.modal.reload();
                } else if (data.code == 500) {
                    $.modal.alertWarning("服务繁忙");
                } else {
                    $.modal.alertWarning(data.message);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });


    }

    function submitHandler() {
        add();
    }


</script>
</body>
</html>